package com.coda.service.impl;

import com.coda.entity.LabelInfo;
import com.coda.mapper.LabelMapper;
import com.coda.service.LabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class LabelServiceImpl implements LabelService {
    @Autowired
    private LabelMapper labelMapper;

    /**
     * 新增或修改标签
     *
     * @param labelInfo
     */
    @Override
    public void saveOrUpdate(LabelInfo labelInfo) {
        //判断是否有id  有：update，没有：insert
        if (labelInfo.getId() == null) {
            labelInfo.setIsDeleted(0);
            labelMapper.insert(labelInfo);
        }else {
            labelMapper.update(labelInfo);
        }

    }

    /**
     * 查询标签列表
     * @return
     */
    @Override
    public List<LabelInfo> getLabelList() {
        List<LabelInfo> labelInfos = labelMapper.list();
        return labelInfos;
    }

    /**
     * 根据id删除标签
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        labelMapper.delete(id);
    }
}
